package com.lulufind.lulu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.lulufind.lulu.model.ImageToken;
import com.lulufind.lulu.model.Post;
import com.lulufind.lulu.model.Result;
import com.lulufind.lulu.model.Wish;
import com.lulufind.lulu.service.ImageService;

@Controller
@RequestMapping("/image")
public class ImageController {
	
	@Autowired
	ImageService imageService;
	
	@ResponseBody
	@RequestMapping(value="/getToken",produces="application/json;charset=UTF-8")
	public String getToken(int userId, String userToken){
		
		Result<ImageToken> rs = imageService.getToken(userId, userToken);
		
		Gson gson = new GsonBuilder().disableHtmlEscaping().create();
		String s = gson.toJson(rs);
		return s;
	}
	
	
	@ResponseBody
	@RequestMapping(value="/changeUserAvatar",produces="application/json;charset=UTF-8")
	public String changeUserAvatar(int userId, String userToken, String userAvatar){
		
		Result<String> rs = imageService.changeUserAvatar(userId, userToken, userAvatar);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/changeWishAvatar",produces="application/json;charset=UTF-8")
	public String changeWishAvatar(int userId, String userToken, int wishId, String wishAvatar){
		
		Result<Wish> rs = imageService.changeWishAvatar(userId, userToken, wishId, wishAvatar);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/changePostCover",produces="application/json;charset=UTF-8")
	public String changePostCover(int userId, String userToken, int postId, String postCover){
		
		Result<Post> rs = imageService.changePostCover(userId, userToken, postId, postCover);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
}
